package com.cy.advice;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Aspect
@Component
public class HttpAspect {
	
	private final static Logger logger = LoggerFactory.getLogger(HttpAspect.class);
	
	@Pointcut("execution(public * com.etc.controller.*.*(..))")
	public void log() {
		
	}
	@Before("log()")
	public void logbefore(JoinPoint point) {
		ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = attributes.getRequest();
		//url
		logger.info("url={}",request.getRequestURI());
		//method
		logger.info("method={}",request.getMethod());
		//IP:Port
		logger.info("IP:PORT={}",request.getRemoteAddr());
		//服务
		logger.info("Class_Method={}",point.getSignature().getDeclaringTypeName()+"."+point.getSignature().getName());
		//参数
		Object[] args = point.getArgs();
		String argsStr = "";
		for (Object object : args) {
			argsStr+=object.toString();
		}
		logger.info("args={}",argsStr);	
	}
	
//	@AfterReturning()
	
}

